package com.czhhx.myedcon.Tool;

import java.util.List;

public class Algorithm {
    /**
     * 自适应显示
     * @param waveList
     * @return
     */
    public static float[] getFloats(List<String> waveList) {
        float []floats;
        int count = 0;
        int len = waveList.size();
        if(len>=720&&len<1400){
            floats = new float[(len-1)/4+1];
            for(int i=0;i<len;i++){
                count++;
                if(count == 4) {
                    count=0;
                    try {
                        floats[i/4]=Float.parseFloat(waveList.get(i));
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
            }
        }else if(360<=len&&len<720){
            floats = new float[(len-1)/2+1];
            for(int i=0;i<len;i++){
                count++;
                if(count == 2) {
                    count=0;
                    try {
                        floats[i/2]=Float.parseFloat(waveList.get(i));
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
            }
        }else if(5<=len&&len<360){
            floats = new float[len];
            for(int i=0;i<len;i++) {
                if(waveList.get(i).equals("-")){
                    floats = new float[0];
                }
                floats[i]=Float.parseFloat(waveList.get(i));
            }
            if(len<180) {
                for (int times = 2; times<100; times = times * 2) {
                    if(times*len<360) {
                        float []tem = new float[times*len-times+1];

                        for(int j = 0; j<(times*len-times)/2; j++){
                            tem[2*j] = floats[j];
                            tem[2*j+1] = (floats[j+1]+floats[j])/2;
                        }
                        tem[(times*len-times)]=floats[(times*len-times)/2];
                        floats = tem;
                    }
                }
            }
        }else {
            floats = new float[0];
        }
        for(int i=0;i<floats.length;i++){
            floats[i]= (float) (floats[i]/1.5-1500);
        }
        return floats;
    }
}
